import matplotlib.pyplot as plt
import numpy as np

from mpl_toolkits.mplot3d import Axes3D

# 创建 3D 数据
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111, projection='3d')

x = np.linspace(-5, 5, 50)
y = np.linspace(-5, 5, 50)
X, Y = np.meshgrid(x, y)
Z = np.sin(np.sqrt(X**2 + Y**2))

# 绘制 3D 曲面
surf = ax.plot_surface(X, Y, Z, cmap='viridis', alpha=0.8)

# 添加颜色条
fig.colorbar(surf, ax=ax, shrink=0.5, aspect=5)

ax.set_title('3D 曲面图')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()